package Web.Request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/RequestDemo1")
public class RequestDemo1  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求方式
        String method=req.getMethod();
        System.out.println(method);
        //GET

        //获取虚拟目录
        String contextPath=req.getContextPath();
        System.out.println(contextPath);
        //打印空,我这里是没有设置

        //获取servlet路径
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        // /RequestDemo1

        //获取get请求参数
        String queryString = req.getQueryString();
        System.out.println(queryString);
        //null,这里我没有请求参数,获取到的参数会使用&分隔开

        //获取请求的URI和URL
        String requestURI = req.getRequestURI();
        System.out.println(requestURI);
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);

        //获取协议和版本
        String protocol = req.getProtocol();
        System.out.println(protocol);

        //获取客户机的IP
        String remoteAddr = req.getRemoteAddr();
        System.out.println(remoteAddr);

    }
}
